{
  Модуль командной консоли

 Интерфейс с пользователем

   версия 0.2 март 2011 prodg@ya.ru D.Kondakov
}
unit CommandConsole;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, IIntgrlTypes, IIntgrlObjcts, IIntgrlBaseCnfg;

{$i calcconfig.inc}

type

  { TCmdConsole }

  TCmdConsole = class(TinlModule)
    procedure GetDefParams(DefParams: TStrings); override;
    function CheckParams: TinlLogicType; override;
    procedure AddDefParams(Params: TStringList); override;
    procedure ResetParams; override;
    procedure ProceedSignal(snlMsg: TinlStringType); override;

    procedure LoginUser;
    function ExeCommand(const cmdLine: TinlStringType): TinlStringType;
  protected
    function GetUnitVersion: TinlModifctn; override;
    procedure DataInit; override;
    procedure DataDone; override;
    function GetModuleType: TModuleType; override;
  private
    FSessions: TFPList;

    conCurSession: TIntgrlSession;
    conCurUser: TIntgrlActor;
  public
    property DefSession: TIntgrlSession read conCurSession;
  end;

const
  CONSmodVer = 1000001;

implementation

{$IFDEF MSWINDOWS}
function tiGetUserName : string;
var userNameBuffer : array[0..255] of char;
    sizeBuffer : DWord;
begin
  SizeBuffer := 256;
  getUserName(userNameBuffer, sizeBuffer);
  result := string(userNameBuffer);
end;
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
function tiGetUserName : string;
begin
  Result := GetEnvironmentVariable('USERNAME');
  if Result = '' then Result := GetEnvironmentVariable('USER');
end;
{$ENDIF LINUX}

{ TCmdConsole }

procedure TCmdConsole.GetDefParams(DefParams: TStrings);
begin
  DefParams.Append('CONS_SYS_AUTH=Использовать системную авторизацию');
end;

function TCmdConsole.CheckParams: TinlLogicType;
begin
  Result := true;
end;

procedure TCmdConsole.AddDefParams(Params: TStringList);
begin
//  inherited AddDefParams(Params);
end;

procedure TCmdConsole.ResetParams;
begin
//  inherited ResetParams;
end;

procedure TCmdConsole.ProceedSignal(snlMsg: TinlStringType);
begin
//  inherited ProceedSignal(snlMsg);
end;

procedure TCmdConsole.LoginUser;
begin
  //              StartNewSession
end;

function TCmdConsole.ExeCommand(const cmdLine: TinlStringType): TinlStringType;
begin
  result := 'это точно '+cmdLine+'?';
end;

function TCmdConsole.GetUnitVersion: TinlModifctn;
begin
  Result := CONSmodVer;
end;

procedure TCmdConsole.DataInit;
var
  curUser: TinlLongNameType;
begin
  curUser := tiGetUserName;
  goInfo('Hello, '+curUser+'!');
//  conCurUser := AuthUser
end;

procedure TCmdConsole.DataDone;
begin

  //goInfo('Bye, '+conCurUser.arName+'.');
end;

function TCmdConsole.GetModuleType: TModuleType;
begin
  Result := mCONS;
end;

end.

